package com.jzoom.zoom.admin.daos;

import com.jzoom.zoom.admin.models.AdminDaoModel;
import com.jzoom.zoom.admin.utils.AdminUtils;
import com.jzoom.zoom.dao.Ar;
import com.jzoom.zoom.token.hex.ClientToken;
import com.jzoom.zoom.web.action.ActionContext;

import java.util.Map;

public class UserDao extends AdminDaoModel {
    public UserDao() {
        super("sys", "sys_user", "id");
    }

    /**
     * 系统的才能看到系统的
     *
     * @param ar
     * @param search
     * @return
     */
    @Override
    protected Ar parseSearch(Ar ar, Map<String, Object> search) {
        ActionContext context = ActionContext.get();
        ClientToken token = AdminUtils.getToken(context);
        boolean isSystemUser = AdminUtils.isSystemUser(token);
        if (!isSystemUser) {
            search.put("<>@role", AdminUtils.SYSTEM);
        }
        return super.parseSearch(ar, search);
    }
}
